﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBProvider;
using DBProvider.Providers;

namespace HealthCommunity.Controls
{
	public partial class UCCourseDetail : System.Web.UI.UserControl
	{
		private ICourseProvider _CourseProvider;

		public int CourseID
		{
			get
			{
				return CommonHelper.QueryStringInt("courseid");
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				BindCourseChapter();
			}
		}

		protected void gvCourseChapter_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.DataItem != null)
			{
				var dataItem = e.Row.DataItem as CourseChapter;
				var hlCourseChapter = e.Row.FindControl("hlCourseChapter") as HyperLink;

				hlCourseChapter.NavigateUrl = "~/CourseChapterDetail.aspx?coursechapterid=" + dataItem.CourseChapterID.ToString();
			}
		}

		private void BindCourseChapter()
		{
			if (CourseID > 0)
			{
				if (_CourseProvider == null)
				{
					_CourseProvider = new CourseProvider();
				}

				gvCourseChapter.DataSource = _CourseProvider.GetCourseChapterByCourse(CourseID);
				gvCourseChapter.DataBind();
			}
		}
	}
}